home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / computerjanitorapp / state.py < prev    next >
Encoding:
Python Source  |  2009-03-04  |  1.5 KB  |  48 lines

  1. # state.py - store persistent state of crufts
  2. # Copyright (C) 2008, 2009  Canonical, Ltd.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16.  
  17. import ConfigParser
  18.  
  19.  
  20. class State(object):
  21.  
  22.     def __init__(self):
  23.         self._cp = ConfigParser.ConfigParser()
  24.  
  25.     def load(self, filename):
  26.         self._cp.read(filename)
  27.     
  28.     def save(self, filename):
  29.         f = file(filename, "w")
  30.         self._cp.write(f)
  31.         f.close()
  32.  
  33.     def is_enabled(self, cruft_name):
  34.         if self._cp.has_section(cruft_name):
  35.             return self._cp.getboolean(cruft_name, "enabled")
  36.         else:
  37.             return True
  38.     
  39.     def enable(self, cruft_name):
  40.         if not self._cp.has_section(cruft_name):
  41.             self._cp.add_section(cruft_name)
  42.         self._cp.set(cruft_name, "enabled", "true")
  43.  
  44.     def disable(self, cruft_name):
  45.         if not self._cp.has_section(cruft_name):
  46.             self._cp.add_section(cruft_name)
  47.         self._cp.set(cruft_name, "enabled", "false")
  48.